<route lang="json5">
{
	style: {
		navigationStyle: 'default',
		navigationBarTitleText: '7号助手',
	},
}
</route>
<template>
	<view class="page">
		<text v-if="userStore?.userInfo?.payment_code?.WX">
			{{ appTxtStore?.appTxt?.my_index2?.payment_button?.wx_code_image }}
		</text>
		<image
			:src="userStore?.userInfo?.payment_code?.WX"
			v-if="userStore?.userInfo?.payment_code?.WX"
			mode="scaleToFill"
			class="payment-code"
		/>

		<wd-button type="primary" v-else @click="uploadCode(1)">
			{{ appTxtStore?.appTxt?.my_index2?.payment_button?.buttons?.wx_code_image?.name }}
		</wd-button>
		<text v-if="userStore?.userInfo?.payment_code?.ALI">
			{{ appTxtStore?.appTxt?.my_index2?.payment_button?.ali_code_image }}
		</text>
		<image
			:src="userStore?.userInfo?.payment_code?.ALI"
			v-if="userStore?.userInfo?.payment_code?.ALI"
			mode="scaleToFill"
			class="payment-code"
		/>
		<wd-button type="primary" v-else @click="uploadCode(2)">
			{{ appTxtStore?.appTxt?.my_index2?.payment_button?.buttons?.ali_code_image?.name }}
		</wd-button>
	</view>
</template>
<script setup>
import { upload } from '@/utils/alioss'
import { http } from '@/utils/http'
import { useUserStore } from '@/store/user'
import { useAppTxtStore } from '@/store/appTxt'

const userStore = useUserStore()
const appTxtStore = useAppTxtStore()

const uploadCode = (type) => {
	uni.showModal({
		title: '提示',
		content:
			'是否确认上传' +
			(type == 1
				? appTxtStore?.appTxt?.my_index2?.payment_button?.wx_code_image
				: appTxtStore?.appTxt?.my_index2?.payment_button?.ali_code_image),
		showCancel: true,
		success: async ({ confirm, cancel }) => {
			if (confirm) {
				let res = await upload()
				console.log('%c [ res ]-54', 'font-size:13px; background:pink; color:#bf2c9f;', res)
				if (res.success) {
					let res1 = await http.post('/Usersd/uploadPaymentImages', {
						type,
						file_name: res.filename,
					})

					if (res1.code == 200) {
						uni.showToast({
							title: res1.msg,
							icon: 'none',
							mask: true,
							duration: 2000,
						})

						await userStore.getUserInfo()
					}
				}
			}
		},
	})
}
</script>
<style lang="scss" scoped>
.page {
	padding-top: 24rpx;
	font-size: 24rpx;

	background-color: #fff;
}

.payment-code {
	width: 400rpx;
	height: 400rpx;
}
</style>
